package com.wz.compilerManual.stacktest;

import com.wz.compilerManual.add.symbol.S_E;
import com.wz.compilerManual.add.symbol.S_Ee;
import com.wz.compilerManual.add.symbol.S_N;
import com.wz.compilerManual.add.symbol.S_Nn;
import com.wz.compilerManual.tree.Node;

import java.util.HashMap;

public class MainStack {
    private InnerStack top;

    public void push(InnerStack innerStack){
        innerStack.setNext(top);
        top = innerStack;
    }

    public InnerStack peek(){
        return top;
    }

    public InnerStack pop(){
        InnerStack innerStack = top;
        top = top.getNext();
        innerStack.setNext(null);
        return innerStack;
    }

//    public static void main(String[] args) {
//        SymbolContent s_e_sc = new SymbolContent(new S_E());
//        InnerStack innerStack1 = new InnerStack();
//        innerStack1.push(s_e_sc);
//        MainStack mainStack = new MainStack();
//        mainStack.push(innerStack1);
//
//
//        SymbolContent s_ee_sc = new SymbolContent(new S_Ee(), mainStack.peek().peek().getNode());
//        SymbolContent s_n_sc = new SymbolContent(new S_N(), mainStack.peek().peek().getNode());
//        InnerStack innerStack2 = new InnerStack();
//        innerStack2.push(s_ee_sc);
//        innerStack2.push(s_n_sc);
//        mainStack.peek().peek().getNode().setChildren(new Node[]{s_n_sc.getNode(), s_ee_sc.getNode()});
//        mainStack.push(innerStack2);
//
//        SymbolContent s_Nn_sc = new SymbolContent(new S_Nn(), mainStack.peek().peek().getNode());
//        InnerStack innerStack3 = new InnerStack();
//        innerStack3.push(s_Nn_sc);
//        mainStack.peek().peek().getNode().setChildren(new Node[]{s_Nn_sc.getNode()});
//        mainStack.push(innerStack3);
//
//        mainStack.pop();
//        mainStack.pop();
//
//        SymbolContent content = mainStack.pop().pop();
//
//        postOrderTraveral(content.getNode());
//    }
//
//    public static void postOrderTraveral(Node node){
//        if(!node.hasChildren()){
//            System.out.println(node.getSymbol().toString());
//            return;
//        }
//        for (Node child : node.getChildren()){
//            postOrderTraveral(child);
//        }
//        System.out.println(node.getSymbol().toString());
//    }
}